package 复制java文件打印流;
import java.io.*;

/*
将CopyJavaDemo.java复制到模块目录下copy1.java
 */
public class CopyJavaDemo {
    public static void main(String[] args) throws IOException {
     /*   //根据数据源创建字符输入流对象
        BufferedReader br=new BufferedReader(new FileReader("D:\\javajhx\\IO\\src\\复制java文件打印流\\CopyJavaDemo.java"));
        //根据目的地创建字符输出流对象
        BufferedWriter bw=new BufferedWriter(new FileWriter("D:\\javajhx\\IO\\src\\copy1.java"));
        //读写数据，复制文件
        String len;
        while ((len=br.readLine())!=null){
            bw.write(len);
            bw.newLine();
            bw.flush();
        }
        br.close();
        bw.close();
    }*/

        //打印流改进
        //根据数据源创建字符输入流对象
        BufferedReader br = new BufferedReader(new FileReader("D:\\javajhx\\IO\\src\\复制java文件打印流\\CopyJavaDemo.java"));
        //根据目的地创建字符输出流对象
        PrintWriter pw = new PrintWriter(new FileWriter("copy1.java"), true);//调用第二个参数为true自动刷新1
        //读写数据，复制文件
        String len;
        while ((len = br.readLine()) != null) {
            pw.println(len);
        }
        pw.close();
        br.close();
    }
}
